using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using Sysgeprava.Entities;

namespace Sysgeprava.Repository.Mapping
{
    public class FINCAMap : EntityTypeConfiguration<FINCA>
    {
        public FINCAMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.Nombre)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.Direccion)
                .IsRequired()
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("FINCA");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.Nombre).HasColumnName("Nombre");
            this.Property(t => t.Direccion).HasColumnName("Direccion");
            this.Property(t => t.IdPropietario).HasColumnName("IdPropietario");
            this.Property(t => t.IdUbigeo).HasColumnName("IdUbigeo");

            // Relationships
            this.HasRequired(t => t.PROPIETARIO)
                .WithMany(t => t.FINCAs)
                .HasForeignKey(d => d.IdPropietario);
            this.HasRequired(t => t.UBIGEO)
                .WithMany(t => t.FINCAs)
                .HasForeignKey(d => d.IdUbigeo);

        }
    }
}
